package com.hb.study.design_patterns.proxy.dynamic_proxy;

import com.hb.study.design_patterns.proxy.GamePlayerImpl;
import com.hb.study.design_patterns.proxy.IGamePlayer;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

/**
 * 动态代理测试
 *
 * @author Mr.Huang
 * @version v0.1, DynamicProxyMain.java, 2020/5/14 16:39, create by huangbiao.
 */
public class DynamicProxyMain {

    public static void main(String[] args) {
        IGamePlayer iGamePlayer = new GamePlayerImpl("zhangsan");
        ClassLoader classLoader = iGamePlayer.getClass().getClassLoader();
        Class<?>[] interfaces = iGamePlayer.getClass().getInterfaces();
        InvocationHandler invocationHandler = new GamePlayerHandler(iGamePlayer);
        IGamePlayer proxy = (IGamePlayer) Proxy.newProxyInstance(classLoader, interfaces, invocationHandler);
        proxy.login("123");
        proxy.killBoss();
        proxy.upgrade();
    }

}

    